<template>
  <div class="Vendor_Management">
    <div class="pubBig Privilege">
      <div class="h0">
        <p class="lt"></p>
      </div>
      <div class="dDownMain">
        <div
          class="twoBox"
          :style="this.$route.query.Token ? 'top:50px;left:10px':'top: 100px;padding:10px'"
        >
          <el-row>
            <el-col :span="12">
              <el-button
                size="small"
                @click="status=99,getTableData()"
                :type="status==99?'primary':''"
              >全部</el-button>
              <el-button
                size="small"
                @click="status=1,getTableData()"
                :type="status==1?'primary':''"
              >已上线</el-button>
              <el-button
                size="small"
                @click="status=0,getTableData()"
                :type="status==0?'primary':''"
              >已下线</el-button>
            </el-col>
            <el-col :span="12">
              <el-button
                style="float:right"
                size="small"
                icon="el-icon-plus"
                @click="open"
              >新增厂商</el-button>
              <el-button
                style="float:right;margin-right:10px"
                size="small"
                icon="el-icon-search"
                @click="page.page=1,getTableData()"
              ></el-button>
              <el-input
                size="small"
                style="display:inline-block;width:30%;float:right;margin-right:10px"
                placeholder="请输入厂商名称/厂商认证编码"
                v-model="search_val"
              ></el-input>
            </el-col>
          </el-row>
          <template>
            <el-table
              :data="tableData"
              style="width: 100%;margin-top:10px"
              v-loading="isLoading"
              height="600"
            >
              <el-table-column
                prop="VendorName"
                label="厂商名字"
              >
              </el-table-column>
              <el-table-column
                prop="VendorAuth"
                label="厂商认证编码"
              >
              </el-table-column>
              <el-table-column
                prop="VendorDesc"
                label="厂商描述"
              >
              </el-table-column>
              <el-table-column
                prop="VendorContact"
                label="联系人"
              >
              </el-table-column>
              <el-table-column
                prop="VendorTel"
                label="联系电话"
              >
              </el-table-column>
              <el-table-column
                prop="VendorEmail"
                label="邮箱"
              >
              </el-table-column>
              <el-table-column
                label="秘钥"
                prop="VendorSecret"
              >
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-view"
                    style="color:#000"
                    @click="VendorSecretInfor(scope.row.VendorSecret)"
                  ></el-button>
                </template>
              </el-table-column>
              <el-table-column label="状态">
                <template slot-scope="scope">
                  <span
                    :style="scope.row.Status == 1 ?'color:#006600': 'color:red'"
                  >{{scope.row.Status == 1 ? '启用': '禁用'}}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    icon="el-icon-edit"
                    @click="edit(scope.row)"
                  ></el-button>
                  <el-button
                    size="mini"
                    @click="Status(scope.row)"
                  >{{scope.row.Status == 1 ? '下线' : '上线'}}</el-button>
                </template>
              </el-table-column>
            </el-table>
          </template>
          <!-- 页码 -->
          <div
            class="block"
            style="text-align:center"
          >
            <el-pagination
              layout="prev, pager, next"
              :total="page.total"
              :page-size="page.limit"
              :current-page="page.page"
              @current-change="page_change"
            >
            </el-pagination>
          </div>
        </div>
        <!-- 弹层 -->
        <el-dialog
          :title="title"
          :visible.sync="dialogVisible"
          width="45%"
          :before-close="handleClose"
          :append-to-body="true"
          :close-on-click-modal="false"
        >
          <el-form
            label-position="right"
            label-width="120px"
            :model="formLabelAlign"
          >
            <el-form-item
              label="厂商名称"
              style="display:inline-block;width:50%"
            >
              <el-input v-model="formLabelAlign.VendorName"></el-input>
            </el-form-item>
            <el-form-item
              label="厂商描述"
              style="display:inline-block;width:50%"
            >
              <el-input v-model="formLabelAlign.VendorDesc"></el-input>
            </el-form-item>
            <el-form-item
              label="联系人"
              style="display:inline-block;width:50%"
            >
              <el-input v-model="formLabelAlign.VendorContact"></el-input>
            </el-form-item>
            <el-form-item
              label="联系人电话"
              style="display:inline-block;width:50%"
            >
              <el-input v-model="formLabelAlign.VendorTel"></el-input>
            </el-form-item>
            <el-form-item
              label="邮箱"
              style="display:inline-block;width:50%"
            >
              <el-input v-model="formLabelAlign.VendorEmail"></el-input>
            </el-form-item>
          </el-form>
          <span
            slot="footer"
            class="dialog-footer"
          >
            <el-button @click="handleClose">取 消</el-button>
            <el-button
              type="primary"
              @click="btn_Ok"
            >确 定</el-button>
          </span>
        </el-dialog>
        <!-- 秘钥弹层 -->
        <el-dialog
          title="秘钥"
          :visible.sync="dialogVisible_infor"
          width="30%"
          :before-close="handleClose_infor"
          :append-to-body="true"
          :close-on-click-modal="false"
        >
          <span>{{VendorSecret}}</span>
          <span
            slot="footer"
            class="dialog-footer"
          >
            <el-button @click="handleClose_infor">关 闭</el-button>
          </span>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data () {
    return {
      tableData: [],
      search_val: '',
      page: {
        page: 1,
        limit: 10,
        total: 1
      },
      status: 99,
      dialogVisible: false,
      formLabelAlign: {},
      isLoading: false,
      dialogVisible_infor: false,
      VendorSecret: '',
      title: ''
    };
  },
  methods: {
    getTableData () { // 获取表格数据
      this.isLoading = true
      this.$post("/ServiceManage/Vendor/PageList?keyword=" + this.search_val + "&page=" + this.page.page + "&limit=" + this.page.limit + "&status=" + this.status).then(res => {
        if (res.code == 0) {
          this.tableData = res.data.list
          this.isLoading = false
        }
      })
    },
    open () { // 打开弹层
      this.formLabelAlign.Id ? this.title = '修改' : this.title = '新增'
      this.dialogVisible = true
    },
    handleClose () { // 关闭弹层事件
      this.dialogVisible = false
      this.formLabelAlign = {}
    },
    edit (val) { // 表格修改时间
      var info = JSON.stringify(val)
      this.formLabelAlign = JSON.parse(info)
      console.log(val);
      this.open()
    },
    Status (val) { // 上线/下线按钮操作事件
      let Status = val.Status == 1 ? 0 : 1
      this.$post("/ServiceManage/Vendor/Updown?id=" + val.Id + "&status=" + Status).then(res => {
        if (res.code == 0) {
          this.getTableData()
          this.$message({
            message: '操作成功',
            type: 'success'
          });
        }
      })
    },
    btn_Ok () { // 弹层确定按钮操作事件
      let url = this.formLabelAlign.Id ? '/ServiceManage/Vendor/Update' : '/ServiceManage/Vendor/Create'
      this.$post(url, this.formLabelAlign).then(res => {
        if (res.code == 0) {
          this.handleClose()
          this.getTableData()
          this.$message({
            message: '操作成功',
            type: 'success'
          });
        }
      })
    },
    page_change (val) { // 页码切换操作事件
      this.page.page = val
      this.getTableData()
    },
    VendorSecretInfor (VendorSecret) { // 秘钥按钮点击事件
      this.VendorSecret = VendorSecret
      this.dialogVisible_infor = true
    },
    handleClose_infor () { // 秘钥弹层关闭事件
      this.dialogVisible_infor = false
      this.VendorSecret = ''
    },
  },
  mounted () {
    // document.getElementById("2").focus();
  },
  created () {
    if (this.$route.query.Token) {
      localStorage.setItem('Token', this.$route.query.Token)
    }
    this.getTableData()
  }
};
</script>
<style lang="scss">
.Vendor_Management {
  .top-input {
    display: inline-block;
    width: 350px;
  }

  .box-top {
    margin-top: 15px;
    margin-left: 5px;
  }
}
</style>
